<template>
    <div class="main-layout">
        <!-- 左侧边栏 -->
        <div class="sidebar-container">
            <!-- 系统 Logo + 名称 -->
            <div class="logo-container">
                <img src="@/assets/logo.png" alt="Logo" class="logo" />
                <span class="system-name">医院智能客服系统</span>
            </div>

            <!-- 菜单 -->
            <el-menu default-active="2" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff"
                active-text-color="#ffd04b" router>
                <template v-for="item in menuData" :key="item.title">
                    <!-- 没有子菜单：直接显示 el-menu-item -->
                    <el-menu-item v-if="!item.children" :index="item.link">
                        <el-icon>
                            <component :is="item.icon" />
                        </el-icon>
                        <span>{{ item.title }}</span>
                    </el-menu-item>

                    <!-- 有子菜单：使用 el-sub-menu -->
                    <el-sub-menu v-else :index="item.title">
                        <template #title>
                            <el-icon>
                                <component :is="item.icon" />
                            </el-icon>
                            <span>{{ item.title }}</span>
                        </template>

                        <!-- 子菜单项 -->
                        <template v-for="child in item.children" :key="child.title">
                            <el-menu-item :index="child.link">
                                {{ child.title }}
                            </el-menu-item>
                        </template>
                    </el-sub-menu>
                </template>
            </el-menu>
        </div>

        <!-- 右侧主内容区域 -->
        <div class="main-content-wrapper">
            <!-- 顶部导航 -->
            <!-- <div class="header">
                <el-row :gutter="20">
                    <el-col :span="12" :offset="20">
                        <el-dropdown style="cursor: pointer;">
                            <div class="user-info">
                                <img :src="userObj.userFace" alt="头像" class="avatar" />
                                <span>{{ userObj.userName }}</span>
                                <i class="el-icon-arrow-down"></i>
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item @click.native="userInfo">个人信息</el-dropdown-item>
                                <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </el-col>
                </el-row>
            </div> -->

            <!-- 主体内容 -->
            <el-main class="main-content">
                <el-breadcrumb v-if="$route.path !== '/main'" style="margin-bottom: 1rem;">
                    <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>{{ $route.meta.title || $route.name }}</el-breadcrumb-item>
                </el-breadcrumb>

                <div v-if="$route.path === '/main'" class="welcome">
                    <h1>欢迎进入本系统</h1>
                </div>

                <!-- 子路由显示区域 -->
                <router-view />
            </el-main>
        </div>
    </div>
</template>

<script setup>
import {
    Message,
    Tools,
    Document,
    ChatDotSquare,
    DataAnalysis
} from '@element-plus/icons-vue'

const menuData = [
    {
        title: '部门管理',
        link: '/main/dept',
        icon: 'Message'
    },
    {
        title: '员工管理',
        link: '/main/employee',
        icon: 'Tools'
    },
    {
        title: '本地知识库',
        link: '/main/knowsledge',
        icon: 'Document'
    },
    {
        title: '智能客服',
        link: '/main/ai_chat',
        icon: 'ChatDotSquare'
    },
    {
        title: '数据分析',
        icon: 'DataAnalysis',
        children: [
            {
                title: '热词统计',
                link: '/main/word_cloud'
            },
            {
                title: '人数统计',
                link: '/main/data_count'
            },
            {
                title: '部门评分',
                link: '/main/dept_score'
            }
        ]
    }
]

// 示例用户对象
const userObj = {
    userName: '张三',
    userFace: 'https://via.placeholder.com/32x32'
}

// 示例方法（根据你的业务逻辑补充）
const userInfo = () => {
    console.log('跳转到个人信息')
}
const logout = () => {
    console.log('退出登录')
}
</script>

<style scoped>
.main-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* 左侧菜单 */
.sidebar-container {
    width: 300px;
    height: 100vh;
    background-color: #545c64;
    color: white;
    display: flex;
    flex-direction: column;
}

.logo-container {
    display: flex;
    align-items: center;
    padding: 20px;
    background-color: #303a47;
    font-size: 18px;
    font-weight: bold;
}

.logo {
    width: 30px;
    height: 30px;
    margin-right: 10px;
}

.system-name {
    font-size: 16px;
}

.el-menu {
    border-right: none;
}

/* 右侧内容区域 */
.main-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.header {
    padding: 15px;
    background-color: #f5f7fa;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 10px;
}

.main-content {
    flex: 1;
    padding: 20px;
    background-color: #f9f9f9;
}

.welcome {
    text-align: center;
    margin-top: 50px;
}
</style>